package com.uab.ia.entidades;

import java.util.ArrayList;

@SuppressWarnings("serial")
public class Camino extends ArrayList<Node> implements Comparable<Camino> {
	
	public boolean creado = false;
	private Double costeA;
	private Double costeH;
	private int nParadas;
	private int Transbordos;

	public Camino(Camino clo) {
		this.costeA = clo.costeA;
		this.costeH = clo.costeH;
		this.nParadas = clo.nParadas;
		this.Transbordos = clo.Transbordos;
		
		for (Node n : clo) {
			this.add(n);
		}
	}

	public Camino getRuta() {
		return this;
	}

	public void setRuta(Camino listaCamino) {
		for (Node n : listaCamino) {
			this.add(n);
		}
	}

	public Double getCosteA() {
		return costeA;
	}

	public void setCosteA(Double coste) {
		this.costeA = coste;
	}
	
	public void setnParadas(int paradas) {
		this.nParadas = paradas;
	}
	
	public int getnParadas(){
		return this.nParadas;
	}
	
	public void setTransborodos(int trans) {
		this.Transbordos = trans;
	}
	
	public int getTransborodos(){
		return this.Transbordos;
	}

	public Camino() {
		costeA = 0.0;
		costeH = 0.0;
		nParadas = 0;
	}

	@Override
	public boolean add(Node object) {
		if (!this.contains(object)) {
			this.add(0, object);
			return true;
		}
		return super.add(object);
	}

	public boolean finalEncontrado(long id) {
		for (Node n : this) {
			if (n.id == id) {
				return true;
			}
		}

		return false;
	}

	public Node getFirst() {
		return this.get(0);
	}

	public int compareTo(Camino c) {
		if (this.getCosteT() > c.getCosteT()) {
			return 1;
		} else if (this.getCosteT() == c.getCosteT()) {
			return 0;
		}
		return -1;
	}

	public Double getCosteH() {
		return costeH;
	}

	public void setCosteH(Double costeH) {
		this.costeH = costeH;
	}

	public Double getCosteT() {
		return this.costeA + this.costeH;
	}

	@Override
	public String toString() {

		StringBuilder str = new StringBuilder("IDS: ");

		for (Node l : this) {
			str.append(l.toString());
			str.append(" - ");
		}

		str.append(" --- COSTE: ");
		str.append(this.getCosteT());
		return str.toString();

	}

	public Node removeFirst() {
		Node n = this.get(0);
		this.remove(0);
		return n;
	}

}
